import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'

const initState = {
    slides: [],
    songs: []
}
function reducer(state = initState, action) {
    if (action.type === 'SAVE_SLIDES') {
        state.slides = action.data.map((item, key) => ({ ...item, key }))
        return { ...state }
    } else if(action.type === 'SAVE_SONGS') {
        state.songs = action.data.map((item, key) => ({ ...item, key }))
        return { ...state }
    }
    return state
}
const store = createStore(reducer, applyMiddleware(thunk))
export default store
